<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title></title>
</head>
<body>
    <div id="root"> </div>

    <script src="../js/react.development.js"></script>
    <script src="../js/react-dom.development.js"></script>
    <script src="../js/babel.min.js"></script>

    <script type="text/babel">
        class App extends React.Component{
            render(){
                return <div>
                        <h2>用户登录</h2>
                        <form action="">
                            用户名: <input type="text" ref={el => this.username = el} /><br/>
                            密码: <input type="password" ref={el => this.password = el}/><br />
                            <input type="submit" value="登录" onClick={this.login} />
                        </form>
                    </div>
            }

            login = (e) => {
                //获取用户名的值
                let user = this.username.value;
                let pass = this.password.value;
                //输出
                console.log('您的用户名: '+ user, '您的密码为:'+ pass);
                //阻止默认行为
                e.preventDefault();
            }
        }

        ReactDOM.render(<App />, document.querySelector("#root"));
    </script>
</body>
</html>